﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
namespace DataCollectionSystem
{
	/// <summary>
	/// MainWindow.xaml 的交互逻辑
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
			try
			{
				DataTable data = ApiService.GetDevices();
				if (data != null)
				{
					dg_devicds.ItemsSource = data.AsDataView();
				}
				else
				{
					MessageBox.Show("该用户没有设备", "提示");
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show("错误请重新登录\r\n"+ex.Message, "提示");
			}

		}

		private void bnt_logout1_Click(object sender, RoutedEventArgs e)
		{
			Logout();
		}
		private void Logout()
		{
			try
			{
				ApiService.Logout();
				LoginWindow loginWindow = new LoginWindow();
				loginWindow.Show();
				this.Close();
			}
			catch
			{ }
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			DataRowView row = (DataRowView)((Button)sender).DataContext;
			string device_id = (string)row.Row[0];
			DataWindow dataWindow = new DataWindow(device_id);
			dataWindow.ShowDialog();

		}
	}
}
